'''
作者：陆永均
查询 select_db(self,sql):需要传入sql语句，返回值将会是一个大元组。
使用该查询方法去需要import这个模块

'''
import pymysql

class Projectdb:


    def insert_db(self,job_name,pay,company,address,tid,region):
        conInfo = pymysql.connect(host="localhost", user="root", password="", db="employ", port=3306,charset="utf8")
        cursor = conInfo.cursor()
        cursor.execute("""INSERT INTO job (id,job_name,pay,company,adress,tid,region )VALUES (NULL,"%s",%d,"%s","%s",%d,"%s")"""%(job_name,pay,company,address,tid,region))
        conInfo.commit()
        conInfo.close()

    def select_db(self,sql):
        conInfo = pymysql.connect(host="45.32.67.39", user="admin", password="00000000", db="employ", port=3306,charset="utf8")
        cursor = conInfo.cursor()
        cursor.execute(sql)
        results = cursor.fetchall()
        return results
        conInfo.close()

    def check(self,address,tid):
        conInfo = pymysql.connect(host="localhost", user="root", password="", db="employ", port=3306,charset="utf8")
        cursor = conInfo.cursor()
        sql = """select * from job where adress='%s' and tid=%d """%(address,tid)
        cursor.execute(sql)
        results = cursor.fetchall()
        print(results)
        conInfo.close()
        return results

if __name__=="__main__":
    db=Projectdb()
    print(db.select_db("select avg(pay) from job where tid=5")[0][0])
    # """INSERT INTO job (id,job_name,pay,company,adress,tid )VALUES (NULL,'jobname','20k','testcomplay','www.baidu.com','1')""")
    # db.select_db()

